import {get, post} from '../fetch/index';
import exportUrl from './exportUrl';

const baseUrl = 'https://store.fdimall.com';
const v1 = 'v1';

/**
 * @param username
 * @param pwd
 * @returns {Promise<* | void>}
 */
export const toLogin = (username, pwd) => {
  return post(`${baseUrl}/${v1}/leologin`, {
    username,
    pwd,
  });
};

/**
 * 历史查看
 * get：https://store.fdimall.com/v1/leohistory
 * params：{
 *   type	否	string	类型
 *   time	否	string	时间
 *   page	是	int	    第几页
 *   page_size  是	int	页数大小
 * }
 */
export const getHistory = async (page = 1, page_size = 1, type, time) => {
  const url = await exportUrl(`${baseUrl}/${v1}/leohistory`);
  return await get(url, {
    page,
    page_size,
    type,
    time,
  });
};

/**
 * 工作站信息
 * get:'https://store.fdimall.com/v1/leoworkstation'
 * @returns {Promise<* | void>}
 */
export const getWorkstation = async () => {
  const url = await exportUrl(`${baseUrl}/${v1}/leoworkstation`);
  return await get(url);
};

/**
 * 获取所有型号
 * https://store.fdimall.com/v1/leospec
 * get
 */
export const getSpec = async () => {
  const url = await exportUrl(`${baseUrl}/${v1}/leospec`);
  return await get(url);
};

/**
 * 提交订单
 * post:'https://store.fdimall.com/v1/leoorder'
 * @param spec_code
 * @param level
 * @param num
 * @returns {Promise<void>}
 */

export const orderSubmit = async (spec_code, level, num) => {
  const url = await exportUrl(`${baseUrl}/${v1}/leoorder`);
  return await post(url, {spec_code, level, num});
};

/**
 * 设定产量;
 * post: 'https://store.fdimall.com/v1/leoworkstation'
 * @param code
 * @param set_output
 * @param is_automatic
 * @returns {Promise<void>}
 */

export const submitSetUp = async (code, set_output, is_automatic) => {
  const url = await exportUrl(`${baseUrl}/${v1}/leoworkstation`);
  return await post(url, {code, set_output, is_automatic});
};
